global dir = "C:\Users\mrueda\Documents\Emory\Papers\Networks_persistance\do_files\do_files_APSA21\post_JOP\Replication_BJPS\"	

cd "$dir"


	global balance_muni lown_resources potencial armed_actor rural_pop_t q_education y_mw
	global balance_ind women age black indi_bkg leftist rightwing sanc_before ilegal pol_exp_d elec_exp_d 
	global balance_fin all total_income donations_total 
	global balance_donors family cont_donor_102 cont_donor_101 contraloria above_lim   
	global balance_all $balance_ind $balance_fin $balance_donors



	
	texdoc close 
	cap erase "$dir/Tables/TableC2.tex"
	texdoc init "$dir/Tables/TableC2.tex", force

	tex \begin{table}[tbph]
	tex \caption{Close-election municipality characteristics}\label{tab:repr}
	tex \begin{center}
	tex \scalebox{.8}{%
	tex {\normalsize
	tex \begin{tabular}{l c c c }
	tex \toprule[1.5pt]
	tex \multicolumn{1}{c}{} & Mean&  Mean & p-value  \\
	tex \multicolumn{1}{c}{} & Margin. $>$ 0.1 &  Margin. $\leq $ 0.1 & $H_0$: \text{No difference in means} \\
	tex \hline
	tex \addlinespace
	
	
	use "Data\muni_charac_rep.dta",clear

	replace potencial=potencial/1000
	replace y_mw=y_mw/100
	
	foreach x in $balance_muni{

		ttest `x', by(close_el)
		
		local mu_1_`x' : di %5.3f `r(mu_1)'
		local mu_2_`x' : di %5.3f `r(mu_2)'
		local p_val_`x' : di %5.3f `r(p)'
	}
	
	
	
	use  "Data\cand_level_persist_rep.dta",clear
	
	drop if margin_victory==.
	gen close_el=0
	replace close_el=1 if abs(margin_victory)<=.1
	
	foreach x in $balance_all{
	
		ttest `x', by(close_el)
		
		local mu_1_`x' : di %5.3f `r(mu_1)'
		local mu_2_`x' : di %5.3f `r(mu_2)'
		local p_val_`x' : di %5.3f `r(p)'
	}
	
	
	
		
	*Table continue
	tex \multicolumn{4}{l}{\textit{Panel A: Municipality characteristics}}\\
	tex \addlinespace
	tex \ Local revenue (\% of total) & `mu_1_lown_resources' & `mu_2_lown_resources' & `p_val_lown_resources' \\
	tex \ Registered voters & `mu_1_potencial' & `mu_2_potencial' & `p_val_potencial' \\
	tex \ Armed group & `mu_1_armed_actor' & `mu_2_armed_actor' & `p_val_armed_actor' \\
	tex \ Rural population & `mu_1_rural_pop_t' & `mu_2_rural_pop_t' & `p_val_rural_pop_t'  \\
	tex \ Underperforming schools & `mu_1_q_education' & `mu_2_q_education' & `p_val_q_education' \\
	tex \ Discretionary revenue & `mu_1_y_mw' & `mu_2_y_mw' & `p_val_y_mw' \\
tex \\
	
	tex \multicolumn{4}{l}{\textit{Panel B: Candidates characteristics}}\\
	tex \addlinespace
	tex \ Women & `mu_1_women' & `mu_2_women' & `p_val_women' \\
	tex \ Age & `mu_1_age' & `mu_2_age' & `p_val_age' \\
	tex \ Black & `mu_1_black' & `mu_2_black' & `p_val_black' \\
	tex \ Indigenous & `mu_1_indi_bkg' & `mu_2_indi_bkg' & `p_val_indi_bkg'  \\
	tex \ Left wing & `mu_1_leftist' & `mu_2_leftist' & `p_val_leftist' \\
	tex \ Right wing & `mu_1_rightwing' & `mu_2_rightwing' & `p_val_rightwing' \\
	tex \ Sanctioned & `mu_1_sanc_before' & `mu_2_sanc_before' & `p_val_sanc_before' \\
	tex \ Illegal Registration of ID. & `mu_1_ilegal' & `mu_2_ilegal' & `p_val_ilegal' \\
	tex \ Political experience & `mu_1_pol_exp_d' & `mu_2_pol_exp_d' & `p_val_pol_exp_d' \\
	tex \ Held office before & `mu_1_elec_exp_d' & `mu_2_elec_exp_d' & `p_val_elec_exp_d' \\
	tex \\
	
	tex \multicolumn{4}{l}{\textit{Panel C: General funding covariates}}\\
	tex \addlinespace	
	tex \ Donors & `mu_1_all' & `mu_2_all' & `p_val_all' \\
	tex \ Campaign revenue & `mu_1_total_income' & `mu_2_total_income' & `p_val_total_income'  \\
	tex \ Donations /Revenue & `mu_1_donations_total' & `mu_2_donations_total' & `p_val_donations_total' \\

	tex \\
	tex \multicolumn{4}{l}{\textit{Panel D: Donors characteristics}}\\
	tex \addlinespace	
	tex \ Family & `mu_1_family' & `mu_2_family' & `p_val_family'\\
	tex \ Avg. Donation (private) & `mu_1_cont_donor_102' & `mu_2_cont_donor_102' & `p_val_cont_donor_102' \\
	tex \ Avg. Donation (family) & `mu_1_cont_donor_101' & `mu_2_cont_donor_101' & `p_val_cont_donor_101' \\
	tex \ Comptroller sanction & `mu_1_contraloria' & `mu_2_contraloria' & `p_val_contraloria' \\
	tex \ Above limit & `mu_1_above_lim' & `mu_2_above_lim' & `p_val_above_lim' \\


	
	tex \addlinespace
	tex \midrule[1 pt]
	tex \end{tabular}
	tex }}
	tex \parbox{160mm}{ \scriptsize{
	tex Local revenue denotes the percentage of own resources in all resources of the municipality. Armed group indicates the presence of guerrillas or paramilitary forces. Underperforming schools is the share of schools in the municipality classified below average performance by the Instituto Colombiano para la Evaluaci\'on de la Educaci\'on. Rural population is the share of the population living in rural areas. Sanctioned indicates the candidate has been sanctioned by the Office of the Inspector General. Donors and Donations include totals for non-family and family donors. Family is the fraction of donors who are family members of the candidate. Above limit is the fraction of donors contributing above the individual legal limit.
	tex }
	tex }
	tex \end{center}
	tex \end{table}
	cap texdoc close
